package com.tengniu.web.controller.base;

import com.tengniu.biz.bo.LocationDataBO;
import com.tengniu.common.core.controller.BaseController;
import com.tengniu.common.core.domain.AjaxResult;
import com.tengniu.comom.service.DropdownService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 区域下拉框选择器
 */
@RestController
@RequestMapping("/admin/locationDropdown")
@Slf4j
public class DropdownLocationController extends BaseController {

    @Resource
    private DropdownService dropdownService;

    /**
     * 中国省份
     *
     * @return
     */
    @GetMapping("/listProvinces")
    public AjaxResult listProvinces() {
        List<LocationDataBO> locationDataBOS = dropdownService.listProvinces();
        return AjaxResult.success(locationDataBOS);
    }

    /**
     * 中国省份下的城市
     *
     * @return
     */
    @GetMapping("/listCities/{code}")
    public AjaxResult listCities(@PathVariable String code) {
        List<LocationDataBO> locationDataBOS = dropdownService.listCities(code);
        return AjaxResult.success(locationDataBOS);
    }

    /**
     * 中国省份下的区
     *
     * @return
     */
    @GetMapping("/listDistricts/{code}")
    public AjaxResult listDistricts(@PathVariable String code) {
        List<LocationDataBO> locationDataBOS = dropdownService.listDistricts(code);
        return AjaxResult.success(locationDataBOS);
    }

}
